<template>
  <div class="icons">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page, index) of pages" :key="index">
        <div class="icon" v-for="item of page" :key="item.id">
          <div class="icon-wrapper">
            <img class="icon-content" :src="item.imgUrl" alt="">
          </div>
          <p class="icon-desc">{{item.desc}}</p>
        </div>
      </swiper-slide>
      <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  props: {
    list: Array
  },
  computed: {
    pages () {
      const pages = []
      this.list.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination'
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import "~styles/varibles.styl"
  @import "~styles/ellipsis.styl"
  .icons
    height: 0
    overflow hidden
    padding-bottom 50%
    background: #fff
  .icons >>> .swiper-container
    height: 0
    overflow visible
    padding-bottom 3.2rem
  .icons >>> .swiper-container-horizontal > .swiper-pagination-bullets
     bottom -.4rem
    .icon
      position relative
      float left
      width 25%
      height 0
      padding-bottom 1.6rem
      overflow hidden
      .icon-wrapper
        position absolute
        left 0
        right 0
        top: 0
        bottom .4rem
        box-sizing border-box
        padding-top .1rem
        .icon-content
          height 100%
          display block
          margin 0 auto
      .icon-desc
        position: absolute
        left 0
        right 0
        bottom 0
        height .4rem
        line-height .4rem
        color $txtColor
        text-align center
        font-size .28rem
        ellipse ()
</style>
